package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil;

import groovy.transform.PackageScope;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * XxlJob开发示例（Bean模式）
 *
 * 开发步骤：
 * 1、在Spring Bean实例中，开发Job方法，方式格式要求为 "public ReturnT<String> execute(String param)"
 * 2、为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")"，注解value值对应的是调度中心新建任务的JobHandler属性的值。
 * 3、执行日志：需要通过 "XxlJobLogger.log" 打印执行日志；
 *
 * @author xuxueli 2019-12-11 21:52:51
 */
@Component
public class SampleXxlJob {
    private static Logger logger = LoggerFactory.getLogger(SampleXxlJob.class);


    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("AllJobHandler")
    public ReturnT<String> demoJobHandler(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, Hello World.");

        String cmd = "cmd /c start D:\\mysql\\全量备份.bat";

        Process ps = Runtime.getRuntime().exec(cmd);

        ps.waitFor();

        	return ReturnT.SUCCESS;
    }

    @XxlJob("AddJobHandler")
    public ReturnT<String> AddJobHandler(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, Hello World.");

        String cmd = "cmd /c start D:\\mysql\\增量备份.bat";

        Process ps = Runtime.getRuntime().exec(cmd);

        ps.waitFor();

        	return ReturnT.SUCCESS;
    }
    
    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("DAllJobHandler")
    public ReturnT<String> DdemoJobHandler(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, Hello World.");

        String cmd = "cmd /c start D:\\mysql\\全量备份D.bat";

        Process ps = Runtime.getRuntime().exec(cmd);

        ps.waitFor();

        	return ReturnT.SUCCESS;
    }

    @XxlJob("DAddJobHandler")
    public ReturnT<String> DAddJobHandler(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, Hello World.");

        String cmd = "cmd /c start D:\\mysql\\增量备份D.bat";

        Process ps = Runtime.getRuntime().exec(cmd);

        ps.waitFor();
       
        	return ReturnT.SUCCESS;
    }


  

}
